package com.zhugang.week05;

/**
 * @program algorithms
 * @description: guessNumber
 * @author: chanzhugang
 * @create: 2022/07/05 15:21
 */
public class GuessNumber extends GuessGame {
    /**
     * 374 猜数字大小
     *
     * @param n
     * @return
     */
    public int guessNumber(int n) {
        // 转为标准二分
        int low = 0;
        int high = n;
        while (low <= high) {
            int mid = low + (high - low) / 2;
            int res = guess(mid);
            if (res == 0) {
                return mid;
            } else if (res == -1) {
                // 猜大了
                high = mid - 1;
            } else {
                low = mid + 1;
            }
        }
        return -1;
    }
}

class GuessGame {
    int guess(int num) {
        return 0;
    }
}

